FROM node:20-alpine AS base

RUN npm config set registry https://registry.npmmirror.com/


ENV PNPM_REGISTRY=https://registry.npmmirror.com/
RUN npm i -g pnpm

FROM base AS dependencies

WORKDIR /home/longriver/longriver-server
COPY package.json pnpm-lock.yaml ./
RUN pnpm install

FROM base AS build

WORKDIR /home/longriver/longriver-server
COPY . .
COPY --from=dependencies /home/longriver/longriver-server/node_modules ./node_modules
RUN pnpm build
RUN pnpm prune --prod

FROM base AS deploy

WORKDIR /home/longriver/longriver-server
COPY --from=build /home/longriver/longriver-server/dist/ ./dist/
COPY --from=build /home/longriver/longriver-server/node_modules ./node_modules

EXPOSE 8000

CMD ["sh", "-c", "node dist/main.js"]
